<%@page pageEncoding="utf-8" contentType="text/html; charset=utf-8" %>
<%@ include file="/cms/include/init_admin.jsp" %>
<%@ page import="com.qbooks.cms.homepage.*" %>
<%

	HashList code003	= CommonUtil.getCodeList("003");	//회원상태
	HashList code004	= CommonUtil.getCodeList("004");	//구매상태

	String job_type		= StringUtil.nvl(request.getParameter("job_type"),"U");
	String member_id	= StringUtil.nvl(request.getParameter("member_id"), "XXX");

	HashMap infos 		= new HashMap();
	infos.put("member_id",	member_id);

	HomepageDAO dao 	= new HomepageDAO();
	HashList list 		= dao.selectMemberList(infos);
	HashList macList	= dao.selectMemberMacList(infos);
	HashList bookList	= dao.selectMemberBookList(infos);


%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<title><%= SYSTEM_NAME %></title>
	<%@ include file="/cms/include/cssnjs.jsp"  %>

	<script type="text/javascript">

	$(document).ready(function() {

		/* 탭 클릭 */
		$('li', '#tabs').click(function(){
		    $('.on', '#tabs').removeClass('on').addClass('off');
		    $(this).addClass('on');

			$('#tabs-1:not(.hidden),#tabs-2:not(.hidden),#tabs-3:not(.hidden)').addClass('hidden');
			$('#tabs-'+$(this).attr('code')).removeClass('hidden');
		});

		$('#list').find('input, select').change(function() {
			$(this).closest('tr').find('input[name="list.job_type"]').val('U');
		});

	});


	function fnSave() {
		if (confirm(MSG_<%=job_type%>)) {
			$('#saveForm').attr('action', './memberSave.do');
			$('#saveForm').submit();
		}
	}


	function fnDelete() {
		if (confirm(MSG_D)) {
			$('#job_type').val('D');
			$('#saveForm').attr('action', './memberSave.do');
			$('#saveForm').submit();
		}
	}

	function fnDeleteMac(mac) {
		if (confirm(MSG_D)) {
			$('#mac').val(mac);
			$('#saveForm').attr('action', './memberMacDelete.do');
			$('#saveForm').submit();
		}
	}

	function fnUpdateOrder() {
		if (confirm(MSG_U)) {
			$('#salesForm').attr('action', './memberSalesSave.do');
			$('#salesForm').submit();
		}
	}
	</script>
</head>
<body>
<div id="wrap">
	<div id="top">
		<%@ include file="/cms/include/top.jsp" %>
	</div>
	<div id="page">
		<div id="menu">
			<%@ include file="/cms/include/leftMenu.jsp" %>
		</div>
		<div id="contents">
			<div class="menu_title">
				<h1>회원관리</h1>
				<p>CMS > 홈페이지  > <b>회원관리</b></p>
			</div>
			<div class="clear line_01"></div>

			<ul id="tabs" class="tab_01 mt15">
			    <li class="on"  code="1"><p>1. 기본사항</p></li>
		<%	if ("U".equals(job_type)) { %>
			    <li class="off" code="2"><p>2. 구매내역</p></li>
		<%	} %>
			</ul>

			<div id="tabs-1" class="mt15">
				<form id="saveForm" method="post" action="">
				<input type="hidden" name="job_type" id="job_type" value="<%= job_type %>"/>
				<input type="hidden" name="mac" id="mac" />
				<table cellpadding="0" cellspacing="0" class="table_01 mt5">
				<colgroup>
					<col width="100px"/>
					<col/>
					<col width="100px"/>
					<col/>
				</colgroup>
				<tbody>
					<tr>
						<th><p>아이디</p></th>
						<td colspan="3" class="brx">
					<%	if ("C".equals(job_type)) { %>
							<input type="text" name="member_id" value=""/>
					<%	} else {	%>
							<%= list.get("member_id", 0) %>
							<input type="hidden" name="member_id" value="<%= list.get("member_id", 0) %>"/>
					<%	}	%>
						</td>
					</tr>
					<tr>
						<th><p>회원명</p></th>
						<td >
							<input type="text" name="member_name" value="<%= list.get("member_name", 0) %>" class="w200"/>
						</td>
						<th><p>상태</p></th>
						<td class="brx">
							<select name="status" class="w100">
							<%= StringUtil.makeOption(code003, list.get("status", 0)) %>
							</select>
						</td>
					</tr>
					<tr>
						<th><p>비밀번호</p></th>
						<td >
		        			<input type="text" name="member_pw" value="<%= list.get("member_pw", 0) %>"  class="w200"/>
						</td>
						<th><p>이메일</p></th>
						<td class="brx">
							<input type="text" name="email" value="<%= list.get("email", 0) %>"  class="w200"/>
						</td>
					</tr>
					<tr>
						<th><p>핸드폰번호</p></th>
						<td>
							<input type="text" name="hp_no" value="<%= list.get("hp_no", 0) %>"  class="w200"/>
	        			</td>
						<th><p>최대 Mac 갯수</p></th>
						<td class="brx">
							<input type="text" name="max_mac" value="<%= list.get("max_mac", 0) %>"  class="w200"/>
						</td>
					</tr>
					<tr>
						<th><p>설명</p></th>
						<td colspan="3" class="brx">
							<textarea name="member_info" class="wmax h120"><%= list.get("member_info", 0) %></textarea>
						</td>
					</tr>
					<tr>
						<th><p>MAC Address</p></th>
						<td colspan="3" class="brx">
					<%	for (int i = 0; i < macList.size(); i++) {	%>
							<%= macList.get("mac", i) %> <a href="#nohref" onclick="fnDeleteMac('<%=macList.get("mac", i)%>')">[삭제]</a><br/>
					<%	} %>
						</td>
					</tr>
				</tbody>
				</table>

				<div class="mt20 mb10 c">
					<a href="./memberList.jsp"><img src="../images/btn_list.gif"/></a>
			<%	if ("U".equals(job_type)) { %>
					<a href="#nohref" onclick="fnSave()"><img src="../images/btn_update.gif" /></a>
					<a href="#nohref" onclick="fnDelete()"><img src="../images/btn_delete.gif" /></a>
			<%	} else if ("C".equals(job_type)) { %>
					<a href="#nohref" onclick="fnSave()"><img src="../images/btn_register.gif" /></a>
			<%	} %>
				</div>

				</form>

			</div>



			<!-- 구매내역 -->
			<div id="tabs-2" class="hidden mt15">

				<form id="salesForm" method="post" action="">
				<input type="hidden" name="member_id" id="member_id" value="<%= member_id %>"/>

				<table cellpadding="0" cellspacing="0" class="table_03 mt5">
				<colgroup>
					<col width="40px"/>
					<col width="200px"/>
					<col width="120px"/>
					<col  />
					<col width="100px"/>
					<col width="100px"/>
				</colgroup>
				<tbody id="list">
					<tr>
						<th><p></p></th>
						<th><p>구매일자</p></th>
						<th><p>큐북코드</p></th>
						<th><p>큐북명</p></th>
						<th><p>금액</p></th>
						<th class="brx"><p>결재상태</p></th>
					</tr>
		<%		for (int i = 0; i < bookList.size(); i++) { %>
					<tr>
					    <td>
					    	<input type="checkbox" name="chk"></input>
					    	<input type="hidden" name="list.job_type" value="X"/>
					    	<input type="hidden" name="list.sales_order" value="<%= bookList.get("sales_order",i) %>"/>
					    </td>
						<td><%= bookList.get("sales_date", i) %></td>
						<td><%= bookList.get("book_code", i) %></td>
						<td><%= bookList.get("book_name", i) %></td>
						<td><%= StringUtil.toPrice(bookList.get("price", i)) %></td>
						<td class="brx">
							<select name="list.status">
							<%= StringUtil.makeOption(code004, bookList.get("status", i)) %>
							</select>
						</td>
					</tr>
		<%		} %>
				</tbody>
				</table>

				<div class="mt20 mb10 c">
					<a href="./memberList.jsp"><img src="../images/btn_list.gif"/></a>
					<a href="#nohref" onclick="fnUpdateOrder()"><img src="../images/btn_update.gif" /></a>
				</div>

				</form>

			</div>



		</div>
	</div>
</div>

</body>
</html>
